#include "minilifesync.h"

MiniLifeSync::MiniLifeSync(QWidget *parent) : QMainWindow(parent), miniLife(new Ui::MiniLifeSync)
{
    miniLife->setupUi(this);

    //Set the mini window with no frame
    this->setWindowFlags(Qt::CustomizeWindowHint);

    readMiniLifeSyncSettings();
}

void MiniLifeSync::readMiniLifeSyncSettings()
{
    QSettings MiniLifeSyncSettings("LifeSync", "Project LifeSync");

    //MiniLifeSync: Mini's Button Load Settings
    miniLife->miniContactsDisplay_Button->setStyleSheet(MiniLifeSyncSettings.value("contactsButtonMini", "QPushButton{background-image: url(:/mainImages/versionOne/miniWindow/images/mainImages/versionOne/miniWindow/contacts.png)}").toString());
    miniLife->miniCalculatorDisplay_Button->setStyleSheet(MiniLifeSyncSettings.value("calculatorButtonMini", "QPushButton{background-image: url(:/mainImages/versionOne/miniWindow/images/mainImages/versionOne/miniWindow/calculator.png)}").toString());
    miniLife->miniChecklistDisplay_Button->setStyleSheet(MiniLifeSyncSettings.value("checklistButtonMini", "QPushButton{background-image: url(:/mainImages/versionOne/miniWindow/images/mainImages/versionOne/miniWindow/checklist.png)}").toString());
    miniLife->miniCalendarDisplay_Button->setStyleSheet(MiniLifeSyncSettings.value("calendarButtonMini", "QPushButton{background-image: url(:/mainImages/versionOne/miniWindow/images/mainImages/versionOne/miniWindow/calendar.png)}").toString());
    miniLife->miniFavoritesDisplay_Button->setStyleSheet(MiniLifeSyncSettings.value("favoritesButtonMini", "QPushButton{background-image: url(:/mainImages/versionOne/miniWindow/images/mainImages/versionOne/miniWindow/favorites.png)}").toString());
    miniLife->miniInfoDisplay_Button->setStyleSheet(MiniLifeSyncSettings.value("infoButtonMini", "QPushButton{background-image: url(:/mainImages/versionOne/miniWindow/images/mainImages/versionOne/miniWindow/info.png)}").toString());
    miniLife->miniSettingsDisplay_Button->setStyleSheet(MiniLifeSyncSettings.value("settingsButtonMini", "QPushButton{background-image: url(:/mainImages/versionOne/miniWindow/images/mainImages/versionOne/miniWindow/settings.png)}").toString());
    miniLife->miniExit_Button->setStyleSheet(MiniLifeSyncSettings.value("quitButtonMini", "QPushButton{background-image: url(:/mainImages/versionOne/miniWindow/images/mainImages/versionOne/miniWindow/quit.png)}").toString());
}

void MiniLifeSync::writeMiniLifeSyncSettings()
{
    QSettings MiniLifeSyncSettings("LifeSync", "Project LifeSync");

    //MiniLifeSync: Mini's Button Save Settings
    MiniLifeSyncSettings.setValue("contactsButtonMini", miniLife->miniContactsDisplay_Button->styleSheet());
    MiniLifeSyncSettings.setValue("calculatorButtonMini", miniLife->miniCalculatorDisplay_Button->styleSheet());
    MiniLifeSyncSettings.setValue("checklistButtonMini", miniLife->miniChecklistDisplay_Button->styleSheet());
    MiniLifeSyncSettings.setValue("calendarButtonMini", miniLife->miniCalendarDisplay_Button->styleSheet());
    MiniLifeSyncSettings.setValue("favoritesButtonMini", miniLife->miniFavoritesDisplay_Button->styleSheet());
    MiniLifeSyncSettings.setValue("infoButtonMini", miniLife->miniInfoDisplay_Button->styleSheet());
    MiniLifeSyncSettings.setValue("settingsButtonMini", miniLife->miniSettingsDisplay_Button->styleSheet());
    MiniLifeSyncSettings.setValue("quitButtonMini", miniLife->miniExit_Button->styleSheet());
}

//Tracks left mouse button clicks
void MiniLifeSync::mousePressEvent(QMouseEvent *mouse)
{
    if (mouse->buttons() == Qt::LeftButton)
    {
        currentPos = mouse->pos();
    }
}

//Tracks mouse move/drag events
void MiniLifeSync::mouseMoveEvent(QMouseEvent *mouse)
{
    if (mouse->buttons() == Qt::LeftButton)
    {
        move(mouse->globalPos() - currentPos);
    }
}

MiniLifeSync::~MiniLifeSync()
{
    delete miniLife;
}

void MiniLifeSync::on_miniExit_Button_clicked()
{
    MiniLifeSync::close();
}
